import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the CommentaddPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-commentadd',
  templateUrl: 'commentadd.html',
})
export class CommentaddPage {
  prodid:any;
  prodcommentlist:any;
  content:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi:BusiProvider,public native:NativeProvider) {
    this.prodid = this.navParams.get("prodid");
    this.getComment();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad CommentaddPage');
  }
  getComment(){
    this.busi.getComment(this.prodid).subscribe(
      data=>{
        this.prodcommentlist = data.prodcommentlist;
      },error=>{}
    );
  }
  addcomment(){
    this.busi.addComment(this.prodid,this.content).subscribe(
      data=>{
        this.native.showToast("留言成功!");
        this.content= "";
        this.getComment();
      },
      error=>{}
    );
  }

}
